package portal.servicios;

import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;

import portal.entidades.Configuracion;
import portal.entidades.MonitoreoLog;
import portal.util.xml.XmlUtil;
import portal.webservices.monitoreo.WSMonitoreo;
import portal.webservices.monitoreo.WSMonitoreoService;

public class InformarSincronicoLyM {

	public static String informarLog(MonitoreoLog log, Configuracion conf) throws Exception {

		String endPoint = conf.getValor();
		// Cargo el namespace del WSDL
		QName qname = new QName("http://webservices/", "WSMonitoreoService");
		// NULL para ignorar el WSDL
		WSMonitoreoService service = new WSMonitoreoService(null, qname);
		WSMonitoreo port = service.getWSMonitoreoPort();
		BindingProvider bindingProvider = (BindingProvider) port;
		// Cargo el endpoint
		bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);

		// Obtengo el XML y lo envio
		String xml = XmlUtil.monitoreoLog2Xml(log);
		String result = port.enviarInformeAuditoria(xml);
		return result;
	}

}
